//定义加载事件
$(function(){
	//创建地图容器
 	china_map =echarts.init(document.getElementById("china_map"),'infographic');
 	function China_map_get(){
        $.ajax({
            url:"../info/queryConfirmCount",
            dataType:"json",
            type:"post",
            success:function (data) {
                option = {
                    title: {
                        text: '新冠型肺炎人口来源分析',
                        textStyle:{color:'#fff'},
                        //subtext: '纯属虚构',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item'
                    },
                    visualMap: {
                        show : false,
                        x: 'left',
                        y: 'bottom',
                        //layoutCenter:['30%','30%'],
                        splitList: [
                            {start: 0, end:100},
                            {start: 100, end: 300},
                            {start: 300, end: 500},
                            {start: 500, end: 800},
                            {start: 800, end: 1500},
                            {start: 1500, end: 100000}
                        ],
                        color: ['red', 'yellow', 'Purple','DarkCyan', 'green', 'Lime']
                    },
                    series: [{
                        name: '新冠型肺炎人口来源分析',
                        type: 'map',
                        mapType: 'china',
                        roam: true,
                        label: {
                            normal: {
                                show: true
                            },
                            emphasis: {
                                show: false
                            }
                        },
                        data:data,
                    }]
                };
                china_map.setOption(option);
                china_map.on("click",function (datas) {
                    loadAreaInfo(datas.name);
                })
            },error:function () {
                layer.alert("服务器错误");
            }
        })
    }
    China_map_get();
    function loadAreaInfo(city) {
        //请求省级地图数据
        $.get("../static/json/" + city + ".json", function (areaJson) {
            //如果要请求服务端的数据
            $.ajax({
                url: "../info/queryEpidemicAreaMapByCity",
                type: "get",
                data: {"provinceName": city},
                dataType: "json",
                success: function (data) {
                    echarts.registerMap(city, areaJson);
                    var option = {
                        title: {
                            text: city + '新冠型肺炎人口来源分析',
                            textStyle: {color: '#fff'},
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        visualMap: {
                            show: false,
                            x: 'left',
                            y: 'bottom',
                            splitList: [
                                {start: 0, end: 100}, {start: 100, end: 300},
                                {start: 300, end: 500}, {start: 500, end: 800},
                                {start: 800, end: 1500}, {start: 1500, end: 100000},
                            ],
                            color: ['red', 'yellow', 'Purple', 'DarkCyan', 'green', 'Lime']
                        },
                        series: [{
                            name: city + '新冠型肺炎人口来源分析',
                            type: 'map',
                            mapType: city,
                            roam: true,
                            label: {
                                normal: {
                                    show: true
                                },
                                emphasis: {
                                    show: false
                                }
                            },
                            data: data
                        }]
                    };
                    china_map.setOption(option);
                    $("#china_map").bind("click",function(){
                        China_map_get();
                    });
                }
            })
        })
    }
})